<script setup>
import {message} from 'ant-design-vue';
import {ref} from 'vue';
import {noticeAdd, noticeUpdate, noticeOne} from '@/api/noticeApi.js';
import * as commonDict from '@/utils/commonDict.js'


const open = ref(false);
const formRef = ref(null);
const emits = defineEmits(['saveSuccessful'])
import {loading} from '@/utils/loadingUtils.js';
import dayjs from 'dayjs';
import {MdEditor} from 'md-editor-v3';
import Base64FilesUpload from '@/components/Base64FilesUpload.vue';

const form = ref({
  title: '',
  content: '',
  files:[],
  publishDate: undefined,
  status: undefined,
  createTime: '',
})


const resetForm = () => {
  formRef.value.resetFields();
  form.value.content=  ''
  form.value.id = ''
};


const submit = async () => {
  if (form.value.content === '') {
    message.error('请输入内容')
  }
  await noticeAdd(form.value)
  message.success('提交成功')
  resetForm()
}

</script>

<template>

  <a-card >
    <a-form :model="form" ref="formRef" layout="vertical">
      <a-form-item
          label="标题"
          name="title"
          :rules="[{ required: true, message: '请输入标题' }]"
      >
        <a-input
            placeholder="请输入标题"
            v-model:value="form.title"></a-input>
      </a-form-item>
      <a-form-item
          label="请上传封面"
          name="files"
          :rules="[{ required: true, message: '请上传封面' }]"
      >
        <base64-files-upload v-model="form.files"></base64-files-upload>
      </a-form-item>

      <a-form-item
          label="内容"
          name="content"
          :rules="[{ required: true, message: '请输入内容' }]"
      >
        <md-editor  v-model="form.content"></md-editor>
      </a-form-item>


      <div class="flex justify-end">
        <a-button type="primary" @click="submit">提交</a-button>
      </div>
    </a-form>
  </a-card>


</template>

<style scoped>

</style>
